//
//  SINAPhotoPopView.m
//  sinashebao
//
//  Created by  androidlongs on 2017/12/28.
//  Copyright © 2017年  androidlongs. All rights reserved.
//

#import "SINAScoreManagerPopView.h"


@interface  SINAScoreManagerPopView()

@property(strong,nonatomic) UILabel *savePhotoUILabel;
@property(strong,nonatomic) UILabel *selectPhotoUILabel;
@property(strong,nonatomic) UILabel *canlePhotoUILabel;
@end
@implementation SINAScoreManagerPopView

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */
- (instancetype)init
{
    self = [super init];
    if (self) {
        
        
        self.bounds = [UIScreen mainScreen].bounds;
        self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.64];
        self.layer.opacity = 0.0;
        
        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(disMiss)];
        self.userInteractionEnabled = YES;
        [self addGestureRecognizer:tap];
        
        [self addSubview:self.contentView];
        
        self.contentView.frame = CGRectMake(self.contentView.frame.origin.x, self.contentView.frame.origin.y, self.contentView.frame.size.width, 140);

        
        
        UILabel *selectPhotoUILabel = [[UILabel alloc]initWithFrame:CGRectMake(0,4, mainW, 44)];
        selectPhotoUILabel.text=@"发布成绩通知";
        
        selectPhotoUILabel.textAlignment=NSTextAlignmentCenter;
        selectPhotoUILabel.textColor=[UIColor colorWithHexString:@"#212121"];
        self.selectPhotoUILabel=selectPhotoUILabel;
        UIView *selectDiviView = [[UIView alloc]initWithFrame:CGRectMake(0, 49, mainW, 1)];
        [selectDiviView setBackgroundColor:[UIColor colorWithHexString:@"#eeeeee"]];
        
        [[SINAUiviewClickLiserner alloc] viewClickFunction:selectPhotoUILabel andWithBlick:^(UIView *view) {
            [self selectPhoneFucntion];
        }];
        
        [self.contentView addSubview:selectDiviView];
        [self.contentView addSubview:selectPhotoUILabel];
        
        UILabel *savePhotoUILabel = [[UILabel alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(selectDiviView.frame)+1, mainW, 44)];
        savePhotoUILabel.text=@"保存";
        
        savePhotoUILabel.textAlignment=NSTextAlignmentCenter;
        savePhotoUILabel.textColor=[UIColor colorWithHexString:@"#212121"];
        
        self.savePhotoUILabel = savePhotoUILabel;
        
        UIView *saveDiviView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(savePhotoUILabel.frame)+1, mainW, 1)];
        [saveDiviView setBackgroundColor:[UIColor colorWithHexString:@"#eeeeee"]];
        
        
        [[SINAUiviewClickLiserner alloc] viewClickFunction:savePhotoUILabel andWithBlick:^(UIView *view) {
            [self savePhoneFucntion];
        }];
       
        
        [self.contentView addSubview:saveDiviView];
        [self.contentView addSubview:savePhotoUILabel];
        
        
        [self.contentView addSubview:selectPhotoUILabel];
        
        UILabel *canlePhotoUILabel = [[UILabel alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(saveDiviView.frame)+1, mainW, 44)];
        canlePhotoUILabel.text=@"取消";
        self.canlePhotoUILabel=canlePhotoUILabel;
        canlePhotoUILabel.textAlignment=NSTextAlignmentCenter;
        canlePhotoUILabel.textColor=[UIColor colorWithHexString:@"#212121"];
        
        
        [[SINAUiviewClickLiserner alloc] viewClickFunction:canlePhotoUILabel andWithBlick:^(UIView *view) {
            [self disMiss];
        }];
        
        
        
        [self.contentView addSubview:canlePhotoUILabel];
        
        
    }
    return self;
}

//发布
-(void)selectPhoneFucntion{
    [self disMiss];
    if (self.uploadBlock) {
        self.uploadBlock();
    }
    
}
//保存
-(void)savePhoneFucntion{
    [self disMiss];
    if (self.saveScoreBlock) {
        self.saveScoreBlock();
    }
}



- (UIView *)contentView
{
    if (!_contentView) {
        _contentView = [[UIView alloc]initWithFrame:CGRectMake(0, mainH, mainW,200)];
        [_contentView setBackgroundColor:[UIColor whiteColor]];
    }
    return _contentView;
}
//显示选择器
- (void)show
{
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    [self setCenter:[UIApplication sharedApplication].keyWindow.center];
    [[UIApplication sharedApplication].keyWindow bringSubviewToFront:self];
    
    
    CGRect frame =  self.contentView.frame;
    frame.origin.y -= self.contentView.frame.size.height;
    [UIView animateWithDuration:0.4 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
        [self.layer setOpacity:1.0];
        self.contentView.frame = frame;
        
    } completion:^(BOOL finished) {
    }];
    
}

//移除选择器
- (void)disMiss
{
    
    CGRect frame =  self.contentView.frame;
    frame.origin.y += self.contentView.frame.size.height;
    [UIView animateWithDuration:0.4 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
        [self.layer setOpacity:0.0];
        self.contentView.frame = frame;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
    
}
@end
